﻿@inherits BaseComponent

<Space Class="kui-nav" Size="@("24")">
    <SpaceItem>
        <Tooltip Title="@Language["Nav.HomePage"]">
            <a href="/"><Icon Type="home" /></a>
        </Tooltip>
    </SpaceItem>
    <SpaceItem Class="kui-nav-full">
        <Tooltip Title="@FullScreenTitle"><Icon Type="@FullScreenIcon" OnClick="OnFullScreen" /></Tooltip>
    </SpaceItem>
    @if (Config.App.IsLanguage)
    {
        <SpaceItem Style="width:40px;text-align:center;"><AntLanguage /></SpaceItem>
    }
    <SpaceItem>
        <AntDropdown Context="Context" Text="@CurrentUser?.Name" Items="UserItems" OnItemClick="e=>OnItemClick(e)" />
    </SpaceItem>
    @if (Config.App.IsTheme)
    {
        <SpaceItem><AntTheme /></SpaceItem>
    }
    <SpaceItem Class="kui-nav-setting">
        <Tooltip Title="@Language["Nav.Setting"]"><Icon Type="setting" OnClick="@(e=>OnMenuClick?.Invoke("setting"))" /></Tooltip>
    </SpaceItem>
</Space>

@code {
    private bool isFullScreen = false;
    private string FullScreenTitle => isFullScreen ? Language["Nav.ExitScreen"] : Language["Nav.FullScreen"];
    private string FullScreenIcon => isFullScreen ? "fullscreen-exit" : "fullscreen";
    private List<ActionInfo> UserItems = [];

    [Parameter] public Action<string> OnMenuClick { get; set; }

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        UserItems.Add(new ActionInfo { Id = "profile", Name = Language["Nav.Profile"], Icon = "user", Url = "/profile" });
        if (CurrentUser.IsSystemAdmin())
            UserItems.Add(new ActionInfo { Id = "SysModuleList", Name = Language.SysModule, Icon = "appstore-add", Url = UIConfig.SysModuleUrl });
        UserItems.Add(new ActionInfo { Id = "logout", Name = Language["Nav.Exit"], Icon = "poweroff" });
    }

    private void OnItemClick(ActionInfo item)
    {
        if (!string.IsNullOrWhiteSpace(item.Url))
            App?.NavigateTo(new MenuInfo { Id = item.Id, Name = item.Name, Icon = item.Icon, Url = item.Url });
        else
            OnMenuClick?.Invoke(item.Id);
    }

    private async void OnFullScreen()
    {
        isFullScreen = !isFullScreen;
        if (isFullScreen)
            await JS.OpenFullScreenAsync();
        else
            await JS.CloseFullScreenAsync();
    }
}